#!/usr/bin/python
# -*- coding: UTF-8 -*-
from socket import *
from time import ctime
COD = 'utf-8'
# 服务器IP
HOST = '127.0.0.1'
# 服务器端端口
PORT = 21566
BUFSIZ = 1024
ADDR = (HOST, PORT)
# 创建socket对象
tcpCliSock = socket(AF_INET, SOCK_STREAM)
try:
    # 连接服务器
    tcpCliSock.connect(ADDR)
    while True:
        data = input('客户端>>>').strip()
        if not data:
            # break
            continue
        # 发送消息
        tcpCliSock.send(data.encode(COD))
        # 读取消息
        data = tcpCliSock.recv(BUFSIZ)
        if not data:
            break
        print(data.decode(COD))
    # 关闭客户端
    tcpCliSock.close()
except:
    print("服务端未启动")